# Contributor: Christoph Reiter <reiter.chrsitoph@gmail.com>
# Contributor: @naveen521kk on Github Naveen M K<naveen@syrusdark.website>

_realname=matplotlib
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.3.4
pkgrel=2
pkgdesc="A python plotting library, making publication quality plots (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://matplotlib.org/'
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-python-pytz"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-cycler"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil"
         "${MINGW_PACKAGE_PREFIX}-python-pyparsing"
         "${MINGW_PACKAGE_PREFIX}-python-pillow"
         "${MINGW_PACKAGE_PREFIX}-python-kiwisolver"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-qhull")
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-certifi")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: Qt5Agg/Qt5Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-gtk3: GTK3Agg/GTK3Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-python-gobject: GTK3Agg/GTK3Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-python-cairo: cairo/GTK3Cairo/Qt5Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-python-tornado: WebAgg backend")
source=("${_realname}-${pkgver}.tar.gz"::"https://pypi.io/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        setupext.py.patch)
sha256sums=('3e477db76c22929e4c6876c44f88d790aacdf3c3f8f3a90cb1975c0bf37825b0'
            '43a13325f23d2be8ef3b1c8f14be0640df690c52742101beb21f7c4eaad30425')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/setupext.py.patch

  cd ${srcdir}
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
   ${MINGW_PREFIX}/bin/python setup.py install -O1 --skip-build \
   --root="${pkgdir}" --prefix=${MINGW_PREFIX}

  install -Dm644 doc/users/license.rst "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-matplotlib/LICENSE
}
